let fs = require('fs');
let user = {
    username: "admin1",
    password: "12345"
};
function reg(){
    let data = fs.readFileSync('./persons.json');
    let arr = JSON.parse(data.toString());
    let s = arr.findIndex(item => item.username == user.username && item.password == user.password);
    if (s >= 0) {
        console.log('用户名已经被占用');
    } else {
        arr.push(user);
        fs.writeFileSync('./persons.json', JSON.stringify(arr));
        console.log('注册成功');
    };
}
reg();